<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class GeneralDocs extends CI_Model
{
	private function MakeLogStr()
	{
		return $this->tank_auth->get_username().' '.date('d.m.y G:i:s');
	}
	
	function GetRecords()
	{
		
	}
	
	function Save($TableName,$KeyID)
	{
		// вставить проверку авторизации
		$PKFieldName = strtolower($this->SysTableColumns->PKFieldName);
		$Data = array();
		foreach ($this->SysTableColumns->Columns as $Column) {
			$ColumnName = $Column['ColumnName'];
			if (strtolower($ColumnName)=='usermodif') {
				$Data[$ColumnName] = '\'Изм '.$this->MakeLogStr().'\' +UserModif';
				$this->db->set($ColumnName,'\'Изм '.$this->MakeLogStr().' \'+UserModif');
			} else if (strtolower($ColumnName)<>$PKFieldName) {
				if ($this->input->post($ColumnName)<>FALSE) {
					$Data[$ColumnName]=$this->input->post($ColumnName);
					$this->db->set($ColumnName,$this->input->post($ColumnName));
				}
			}
		}
		echo "$TableName <br/>";
		echo "$KeyID <br/>";
		print_r($Data);
		//$this->db->where();
		//$this->db->update($TableName,$Data);
	}
}
